<template>
  <div>
    <div class="container-fluid">
      <div class="row spannel_list">
        <div class="col-sm-3 col-xs-6">
          <div class="spannel">
            <em>10015</em><span>篇</span>
            <b>总文章数</b>
          </div>
        </div>
        <div class="col-sm-3 col-xs-6">
          <div class="spannel scolor01">
            <em>123</em><span>篇</span>
            <b>日新增文章数</b>
          </div>
        </div>
        <div class="col-sm-3 col-xs-6">
          <div class="spannel scolor02">
            <em>35</em><span>条</span>
            <b>评论总数</b>
          </div>
        </div>
        <div class="col-sm-3 col-xs-6">
          <div class="spannel scolor03">
            <em>123</em><span>条</span>
            <b>日新增评论数</b>
          </div>
        </div>
      </div>
    </div>

    <div class="container-fluid">
      <div class="row curve-pie">
        <div class="col-lg-8 col-md-8">
          <div class="gragh_pannel" id="curve_show"></div>
        </div>
        <div class="col-lg-4 col-md-4">
          <div class="gragh_pannel" id="pie_show"></div>
        </div>
      </div>
    </div>

    <div class="container-fluid">
      <div class="column_pannel" id="column_show"></div>
    </div>
  </div>
</template>

<script>
import * as echarts from 'echarts'
import { getCurve, getPie } from './home.js'
export default {
  name: 'mainCount',
  data () {
    return {}
  },
  methods: {
    async curve () {
      var myChart = echarts.init(document.getElementById('curve_show'))
      let res = await getCurve()
      // console.log(res);
      let xData = []
      let yData = []
      res.data.date.forEach(item => {
        xData.push(item.date)
        yData.push(item.count)
      })
      var option = {
        tooltip: {
          trigger: 'axis',
          position: function (pt) {
            return [pt[0], '10%']
          }
        },
        title: {
          left: 'center',
          text: '月新增文章数'
        },
        legend: {
          top: 30,
          data: ['新增文章']
        },
        toolbox: {
          show: true,
          feature: {
            dataZoom: {
              yAxisIndex: 'none'
            },
            dataView: { readOnly: false },
            magicType: { type: ['line', 'bar'] },
            restore: {},
            saveAsImage: {}
          }
        },
        xAxis: {
          type: 'category',
          data: xData
        },
        yAxis: {
          type: 'value',
          boundaryGap: [0, '100%'],
          axisLine: {
            show: true
          },
          axisTick: { show: true }
        },

        series: [
          {
            name: '新增文章',
            type: 'line',
            smooth: true,
            symbol: 'emptyCircle',
            sampling: 'lttb',

            itemStyle: {
              color: 'rgb(241, 149, 43)'
            },
            areaStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: 'rgb(254, 234, 212)'
                },
                {
                  offset: 1,
                  color: 'rgb(255, 254, 249)'
                }
              ])
            },
            data: yData
          }
        ]
      }

      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option)
    },
    async pie () {
      var myChart = echarts.init(document.getElementById('pie_show'))
      let res = await getPie()
      console.log(res)
      let list = []
      res.data.date.forEach(item => {
        list.push({ value: item.articles, name: item.name })
      })
      console.log(list)

      var option = {
        title: {
          text: '分类文章数量比',
          left: 'center'
        },
        tooltip: {
          trigger: 'item'
        },
        legend: {
          top: '10%',
          left: 'center'
        },
        color: ['#5885e8', '#13cfd5', '#00ce68', '#ff9565', '#20ff19'],
        series: [
          {
            name: '分类文章数量比',
            type: 'pie',
            radius: ['30%', '50%'],
            avoidLabelOverlap: false,
            emphasis: {
              label: {
                show: true,
                fontSize: '30',
                fontWeight: 'bold'
              }
            },
            labelLine: {
              show: true
            },
            data: list
          }
        ]
      }

      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option)
    },
    column () {
      var myChart = echarts.init(document.getElementById('column_show'))

      var option = {
        title: {
          text: '分类访问量',
          left: 'center'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            // 坐标轴指示器，坐标轴触发有效
            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        color: ['#5885e8', '#13cfd5', '#00ce68', '#ff9565', '#20ff19'],
        legend: {
          top: 30,
          data: ['爱生活', '趣美味', '爱旅行', '爱电影', '爱游泳']
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            data: ['一月', '二月', '三月', '四月']
          }
        ],
        yAxis: [
          {
            type: 'value',
            axisLine: {
              show: true
            },
            axisTick: {
              show: true
            }
          }
        ],
        series: [
          {
            name: '爱生活',
            type: 'bar',
            emphasis: {
              focus: 'series'
            },
            data: [320, 332, 301, 334]
          },
          {
            name: '趣美味',
            type: 'bar',
            emphasis: {
              focus: 'series'
            },
            data: [120, 132, 101, 134]
          },
          {
            name: '爱旅行',
            type: 'bar',
            emphasis: {
              focus: 'series'
            },
            data: [220, 182, 191, 234]
          },
          {
            name: '爱电影',
            type: 'bar',
            emphasis: {
              focus: 'series'
            },
            data: [150, 232, 201, 154]
          },
          {
            name: '爱游泳',
            type: 'bar',
            data: [300, 210, 412, 369],
            emphasis: {
              focus: 'series'
            },
            markLine: {
              lineStyle: {
                type: 'dashed'
              },
              data: [[{ type: 'min' }, { type: 'max' }]]
            }
          }
        ]
      }

      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option)
    }
  },
  mounted () {
    this.curve()
    this.pie()
    this.column()
  }
}
</script>

<style></style>
